﻿using MediatR;
using SlaughterItem.Common.Domains.PORk;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace SlaughterItem.API.Application.Commands.Week02.POOK.ShowWhitePork
{
    public class ShowWhitePorkHandler : IRequestHandler<ShowWhitePorkCommand, Result>
    {
        public ShowWhitePorkHandler(IBaseRepository<WhiteporkData> whiteporkDataRepository)
        {
            WhiteporkDataRepository = whiteporkDataRepository;
        }

        public IBaseRepository<WhiteporkData> WhiteporkDataRepository { get; set; }
        public async Task<Result> Handle(ShowWhitePorkCommand request, CancellationToken cancellationToken)
        {
            var result=new Result() { Code=(int)CommonErrorCode.Search};
            var list = WhiteporkDataRepository.GetAll().Where(x=>x.IsDel==false).ToList();
            if (list != null)
            {
                result.Data = list;
                result.Code = (int)CommonErrorCode.Success;
                return result;
            }
            else
            { 
                return result;
            }
        }
    }
}
